import { AxiosPromise } from "axios";
import { FileInfo } from "./types";
import request from "../../utils/request.ts";

/**
 * 上传文件
 *
 * @param file
 */
export function ApiUploadFile(file: File): AxiosPromise<FileInfo> {
  const formData = new FormData();
  formData.append("file", file);
  return request({
    url: "/api/app/file/upload-file",
    method: "post",
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
}

/**
 * 删除文件
 *
 * @param filePath 文件完整路径
 */
// export function deleteFileApi(filePath?: string) {
//   return request({
//     url: "/api/v1/files",
//     method: "delete",
//     params: { filePath: filePath },
//   });
// }

/**
 * 获取文件，使用文件流的方式
 */
export function ApiGetfile(params: any) {
  return request({
    url: "/api/app/file/download-with-stream",
    method: "get",
    responseType: "arraybuffer",
    params,
  });
}
